<template>
    <div>
        <div style="margin-top: 10%;margin-right: 30%;margin-left: 30%;width:300px">
            <el-form ref="form" :model="form" label-width="80px">
                <el-form-item label="标签ID">
                    <el-input v-model="form.name"></el-input>
                </el-form-item>
                <el-form-item label="货物类型">
                    <el-select v-model="form.value1" style="width: 220px;">
                      <el-option v-for="item in options1" :key="item.id" :value="item.id" :label="item.goods_name"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="分配用户">
                    <el-select v-model="form.value2" style="width: 220px;">
                      <el-option v-for="item in options2" :key="item.id" :label="item.username" :value="item.id"></el-option>
                    </el-select>
                </el-form-item>              
                <el-form-item>
                    <el-button type="primary" @click="onSubmit">立即添加</el-button>
                </el-form-item>
                </el-form>
        </div>
    </div>
</template>

<script>
import {user_info,getgoods,add_lable} from '../../api/api.js'
export default {
    data() {
      return {
        form: {
          name: '',
          value1: '',
          value2: '',     
        },
        options1: [],
        options2: [],
      }
    },
    mounted:function(){
      this.get_user(),
      this.get_goods()
    },
    methods: {
      //获取货物
      get_goods(){
        var params = {
        };
        getgoods(params).then(res=>{
          console.log(res)
            this.options1=res
        })
      },
      //获取用户
      get_user(){
        var params = {
            uid:localStorage.getItem('uid')
        };
        user_info(params).then(res=>{
          console.log(res)
            this.options2=res
        })
      },
      onSubmit() {
        console.log(this.form.value2,this.form.value1,this.form.name);
        var params = {
              create_name:localStorage.getItem('username'),
              lable_id : this.form.name,
              send_uid : this.form.value2,
              cargo_type_id : this.form.value1,
            };
            add_lable(params).then(res=>{
              this.$message(res.message)
          })
      }
    }
}
</script>

<style>

</style>